<?php

namespace Appstore\Model;


use Think\Model;

class AppstoreShopModel extends Model
{

    protected $tableName = 'appstore_shop';
    /* 用户模型自动完成 */
    protected $_auto = array(
        array('create_time', NOW_TIME, self::MODEL_INSERT),
        array('update_time', NOW_TIME),
    );

    public function resetShopData($ids = array())
    {
        if (!empty($ids)) {
            $map['uid'] = array('in', $ids);
        }

        $shops = $this->where($map)->select();
        $result = 0;
        foreach ($shops as &$v) {
            $v['goods_count'] = D('AppstoreGoods')->where(array('uid' => $v['uid'], 'status' => 1))->count();
            $v['sales_count'] = D('AppstoreGoods')->where(array('uid' => $v['uid'], 'status' => 1))->sum('sales');
            if ($this->save($v)!==false) {
                $result++;
            }
        }
        return $result;
    }

}